package top.zywork.query;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 分页查询对象<br/>
 * 创建于2017-08-23<br/>
 *
 * @author 王振宇
 * @version 1.0
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageQuery extends BaseQuery {

    private static final long serialVersionUID = 2691743450470042585L;

    private static final int DEFAULT_PAGE_SIZE = 10;

    /**
     *  第几页
     */
    private Integer pageNo = 1;
    /**
     * 每页多少项
     */
    private Integer pageSize = DEFAULT_PAGE_SIZE;
    /**
     * 排序字段
     */
    private String sortColumn;
    /**
     * 排序规则
     */
    private String sortOrder;

    public Integer getPageNo() {
        return pageNo > 0 ? pageNo : 1;
    }

    public void setPageNo(Integer pageNo) {
        this.pageNo = pageNo > 0 ? pageNo : 1;
    }

    public Integer getPageSize() {
        return pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE;
    }

    public int getBeginIndex() {
        return ((pageNo > 0 ? pageNo : 1) - 1) * (pageSize > 0 ? pageSize : DEFAULT_PAGE_SIZE);
    }

}
